/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.admin;

import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import model.CvFacade;
import model.EmployeeFacade;
import model.Interview;
import model.InterviewFacade;

/**
 *
 * @author Administrator
 */
@ManagedBean(name = "rinmb")
@SessionScoped
public class RoleInterViewManagedBean {
    @EJB
    private EmployeeFacade employeeFacade;
    @EJB
    private CvFacade cvFacade;
    Date date = new Date();

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }
    

    private String CvID;
    private String EmployeeID;

    public String getCvID() {
        return CvID;
    }

    public void setCvID(String CvID) {
        this.CvID = CvID;
    }

    public String getEmployeeID() {
        return EmployeeID;
    }

    public void setEmployeeID(String EmployeeID) {
        this.EmployeeID = EmployeeID;
    }
    
   @EJB
    private InterviewFacade interviewFacade;
    
    private Interview in = new Interview();

    public InterviewFacade getInterviewFacade() {
        return interviewFacade;
    }

    public void setInterviewFacade(InterviewFacade interviewFacade) {
        this.interviewFacade = interviewFacade;
    }

    public Interview getIn() {
        return in;
    }

    public void setIn(Interview in) {
        this.in = in;
    }
    public RoleInterViewManagedBean() {
    }
    
    public List<Interview> interList() {
        return this.interviewFacade.findAll();
    }
    public String interEdit(Interview inter) {
        
        this.in = inter;
        return "EditInterView";
    }
     public String editInter() {
        String page ="";
            int li = interList().size();
            for (int i = 0; i < li; i++) {
                if (interList().get(i).getInterviewID().equals(this.in)){
                    page="EditIterview";
                }else
                {
                    this.in = this.in;
                }
            }
            if(this.in.getEndedTime().getDate()-this.in.getStartedTime().getDate() > 0){
                this.in.setEmployeeID(this.employeeFacade.find(this.EmployeeID));
                        this.in.setCvid(this.cvFacade.find(this.CvID));
                        this.interviewFacade.edit(in);
                        page ="ListInter";
            }
            else{
                
                 page="EditInterview";
            }
                         
                
            
        return page;
        
    }
     public String interView(Interview inter) {
        this.in = inter;
        return "View";
    }
}
